<?php
/**
 * Controller zmeny hesla
 * @author Tomas Srna
 * @package bakalarka
 */

class PasswdController extends Controller
{
	protected $resource = 'index';
	/**
	 * Akcia index
	 */
	function index()
	{
		$t = Template::instance();
		
		$t->title = L::selected()->passwordChange;
		
		$model = Auth::instance()->getUser();
		
		if(getenv('REQUEST_METHOD') == 'POST')
		{
			$f = new PasswdForm($t, $_POST);
			
			if($f->validate())
			{
				$model->password_hash = 
					hash(Config::$hash_function, $_POST['password']);
				
				$model->save();
				
				Logger::log('L::objectChanged_s;'.
						json_encode((string)$model), 'info');
						
				$this->autoredir();
			}
			else
				$t->error = L::selected()->invalidForm;
		}
		else
		{
			$f = new PasswdForm($t, array());
		}
		
		$fw = new FormWriter($f);
		$t->fw = $fw;
		
		$t->render('form');
	}
}
